<template>
  <el-row class="container">
    <el-col :span="24" class="header">
      <el-col :span="10" class="logo" :class="collapsed?'logo-collapse-width':'logo-width'">
        {{collapsed?'':sysName}}
      </el-col>
      <el-col :span="4">
        <div class="tools" @click.prevent="collapse">
          <i class="el-icon-menu"></i>
        </div>
      </el-col>
      <el-col :span="10" class="userinfo">
        <el-dropdown trigger="hover">
          <span class="el-dropdown-link userinfo-inner">{{sysUserName}}</span>
          <el-dropdown-menu slot="dropdown">
           <!--  <el-dropdown-item>我的消息</el-dropdown-item>
            <el-dropdown-item>设置</el-dropdown-item> -->
            <el-dropdown-item  @click.native="changePassword">修改密码</el-dropdown-item>
            <el-dropdown-item  @click.native="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-col>
    </el-col>
    <el-col :span="24" class="main">
      <aside :class="collapsed?'menu-collapsed':'menu-expanded'">
        <!--导航菜单-->
        <el-menu :default-active="$route.path" id="lastclass" class="el-menu-vertical-demo" @open="handleopen" @close="handleclose" @select="handleselect" unique-opened router v-show="!collapsed"  background-color="#324057" text-color="#fff" active-text-color="#ffd04b">
          <template v-for="(item,index) in $router.options.routes" v-if="!item.hidden">
            <el-submenu :index="index+''" v-if="item.type == 1">
              <template slot="title"><i :class="item.iconCls"></i>{{item.name}}</template>
              <el-menu-item v-for="child in item.children" :index="child.path" :key="child.path" v-if="!child.hidden  && child.type==1">
                {{child.name}}
              </el-menu-item>
              <el-submenu :index="child.path" :key="child.path" v-if="child.children && !child.hidden && child.type==1&&child.children[0].type===1" v-for="(child, index) in item.children">
                <template slot="title">{{child.name}}</template>
                <el-menu-item :index="subchild.path" :key="subchild.path"  v-if="!subchild.hidden&&subchild.type === 1" v-for="subchild in child.children">{{subchild.name}}</el-menu-item>
              </el-submenu>
            </el-submenu>
            <el-menu-item v-if="item.leaf&&item.children.length>0&&item.children[0].type===1"  :index="item.children[0].path"><i :class="item.iconCls"></i>{{item.children[0].name}}</el-menu-item>
          </template>
        </el-menu>

        <!--导航菜单-折叠后-->
        <ul class="el-menu el-menu-vertical-demo collapsed" v-show="collapsed" ref="menuCollapsed">
          <li v-for="(item,index) in $router.options.routes" v-if="!item.hidden" class="el-submenu item">
            <template v-if="!item.leaf">
              <div class="el-submenu__title" style="padding-left: 20px;" @mouseover="showMenu(index,true)" @mouseout="showMenu(index,false)"><i :class="item.iconCls"></i></div>
              <ul class="el-menu submenu" :class="'submenu-hook-'+index" @mouseover="showMenu(index,true)" @mouseout="showMenu(index,false)"> 
                <li v-for="child in item.children" v-if="!child.hidden" :key="child.path" class="el-menu-item" style="padding-left: 40px;" :class="$route.path==child.path?'is-active':''" @click="$router.push(child.path)">{{child.name}}</li>
              </ul>
            </template>
            <template v-else>
              <li class="el-submenu">
                <div class="el-submenu__title el-menu-item" style="padding-left: 20px;height: 56px;line-height: 56px;padding: 0 20px;" :class="$route.path==item.children[0].path?'is-active':''" @click="$router.push(item.children[0].path)"><i :class="item.iconCls"></i></div>
              </li>
            </template>
          </li>
        </ul>
      </aside>
      <section class="content-container">
        <div class="grid-content bg-purple-light">
          <!-- <el-col :span="24" class="breadcrumb-container">
            <strong class="title">{{$route.name}}</strong>
            <el-breadcrumb separator="/" class="breadcrumb-inner">
              <el-breadcrumb-item v-for="item in $route.matched" :key="item.path">
                {{ item.name }}
              </el-breadcrumb-item>
            </el-breadcrumb>
          </el-col> -->
          <el-col :span="24" class="content-wrapper">
            <keep-alive><router-view></router-view></keep-alive>
<!--           <router-view></router-view> -->
          </el-col>
        </div>
      </section>
    </el-col>
  </el-row>
</template>

<script>
	/*
	 *获取用户配置信息
	 * */
  import { userGetRoleConfig, changPwd } from '@/assets/util/api.js'
  export default {
    data() {
      return {
        sysName:'泛美后台管理系统',
        collapsed:false,
        sysUserName: '',
        //公共配置项
        questionType:[{type:"single_choice",describ:"单选题"},{type:"multi_choice",describ:"多选题"},{type:"check",describ:"判断题"},{type:"fill",describ:"填空题"},{type:"brief",describ:"简答题"},{type:"audio",describ:"音频题"}],
        userType:[{type:"1",describ:"超级管理员"},{type:"2",describ:"管理员"},{type:"3",describ:"团队管理员"},{type:"4",describ:"招生老师"},{type:"5",describ:"出差安排管理员"},{type:"6",describ:"面试官"},{type:"7",describ:"学生"},{type:"8",describ:"行政人员"}],
        wordBook:[{type:"text",describ:"单行文字"},{type:"textarea",describ:"多行文字"},{type:"date",describ:"日期"},{type:"number",describ:"数字"},{type:"pic",describ:"图片"},{type:"range",describ:"范围"},{type:"kv",describ:"数据字典"},],//数据字典类型
        access_token:"",
      }
    },
    methods: {
      handleopen() {
        //console.log('handleopen');
      },
      handleclose() {
        //console.log('handleclose');
      },
      handleselect: function (a, b) {
      },
      //退出登录
      logout: function () {
        var _this = this;
        this.$confirm('确认退出吗?', '提示', {
          //type: 'warning'
        }).then(() => {
        	("set","checked",_this.checked);
        	if(_this.inStorage("get","checked")){
        		 _this.inStorage("clear","access_token");
          	_this.inStorage("clear","refresh_token");
        	}else{
        		_this.inStorage("clear");
        	}
          _this.$router.push('/');
        }).catch(() => {

        });
      },
      //折叠导航栏
      showMenu(i,status){
        this.$refs.menuCollapsed.getElementsByClassName('submenu-hook-'+i)[0].style.display=status?'block':'none';
      },
      collapse:function(){
        this.collapsed=!this.collapsed;
        var uiwidth = document.getElementById('lastclass');
        if(uiwidth.offsetWidth===0){
        uiwidth.style.width = "230px"
        }
      },
      getUserRole(){
      	
      },
      changPwd(password){
      	var _this = this;
      	var params = {
      		access_token:this.access_token,
      		username:this.sysUserName,
      		password:password
      	}
      	changPwd(this,params).then((res)=>{
      		if(res.data.state == true){
					    _this.$message.success("修改成功！")
					}
      		
					if(res.data.code){
						 _this.$message.error(_this.publicMsg(res.data.code,res.data.error));
					}
      	})
      },
      changePassword(){
      	this.$prompt('请输入新密码', '修改', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPattern: /\S{6,}/,
          inputErrorMessage: '密码不能小于6位！'
        }).then(({ value }) => {
          this.changPwd(value);
        })
      },
    },
    mounted() {
    var _this = this;
//  this.isLogin(this);
//  var access_token = _this.inStorage("gets","access_token");
//		var params = {access_token:access_token}
//  userGetRoleConfig(this,params).then((res)=>{
//				if(res.data.state){
//					_this.inStorage("set","inUserRole",res.data.data)
//				}
//  })
    this.sysUserName = this.inStorage("get","userInfo") || '';
    this.inStorage("set","questionType",this.questionType);
    this.inStorage("set","userType",this.userType);
    this.inStorage("set","wordBook",this.wordBook);
    var userperadmin = JSON.parse(localStorage.getItem("userperadmin"));
    let userPermission = JSON.parse(unescape(sessionStorage.getItem('userPermiss')));
		this.access_token = this.inStorage("get","access_token");
      try {
//         // 导航权限
//        for (var i = 0; i < userPermission.data.length; i++) {
//           for (var j = 0; j < router.length; j++) {
//               if (userPermission.data[i].meta === router[j].meta) {
//                  router[j].hidden = userPermission.data[i].show =='0'?true:false;
//                  // 根据后台数据改变路由名字 
//                  // router[j].name = userPermission.data[i].meta_name;
//                  // 导航孩子路由
//                  for (var m = 0; m < userPermission.data[i].children.length; m++) {
//                     for (var k = 0; k <router[j].children.length; k++) {
//                        if (userPermission.data[i].children[m].meta == router[j].children[k].meta) {
//                          router[j].children[k].hidden = userPermission.data[i].children[m].show == '0'?true:false;
//                          // console.log(router[j].children[k])
//                          // 对报表中心用户行为的概况，分析进行单独权限处理
//                          if (router[j].children[k].meta === '0204') {
//                            if (router[j].children[k].children && router[j].children[k].children.length>0) {
//                                for (var n = 0; n <router[j].children[k].children.length; n++) {
//                                  for (var s = 0; s <userPermission.data[i].children[m].children.length; s++) {
//                                    if (router[j].children[k].children[n].meta === userPermission.data[i].children[m].children[s].meta) {
//                                       router[j].children[k].children[n].hidden = userPermission.data[i].children[m].children[s].show == '0'?true:false;
//                                    }
//                                  } 
//                                }
//                            }
//                          }
//                          // 根据后台数据改变路由名字
//                          // router[j].children[k].name = userPermission.data[i].children[m].meta_name;
//                        };
//                     };
//                  };
//                };
//           };
//        };
      } catch(e) {
        // statements
        console.log(e);
      }
    }
  }

</script>

<style scoped lang="scss">
  .container {
    position: absolute;
    top: 0px;
    bottom: 0px;
    width: 100%;
    .header {
      height: 60px;
      line-height: 60px;
      background: #1f2d3d;
      color:#fff;
      .userinfo {
        text-align: right;
        padding-right: 35px;
        float: right;
        .userinfo-inner {
          cursor: pointer;
          color:#fff;
          img {
            width: 40px;
            height: 40px;
            border-radius: 20px;
            margin: 10px 0px 10px 10px;
            float: right;
          }
        }
      }
      .logo {
        //width:230px;
        height:60px;
        font-size: 18px;
        padding-left:20px;
        padding-right:20px;
        border-color: rgba(238,241,146,0.3);
        border-right-width: 1px;
        border-right-style: solid;
        img {
          width: 40px;
          float: left;
          margin: 10px 10px 10px 18px;
        }
        .txt {
          color:#fff;
        }
      }
      .logo-width{
        width:230px;
      }
      .logo-collapse-width{
        width:60px
      }
      .tools{
        padding: 0px 23px;
        width:14px;
        height: 60px;
        line-height: 60px;
        cursor: pointer;
      }
    }
    .main {
      display: flex;
      // background: #324057;
      position: absolute;
      top: 60px;
      bottom: 0px;
      overflow: hidden;
      aside {
        flex:0 0 230px;
        width: 230px;
        // position: absolute;
        // top: 0px;
        // bottom: 0px;
        .el-menu{
          height: 100%;
          text-align: left;
        }
        .collapsed{
          width:60px;
          .item{
            position: relative;
          }
          .submenu{
            position:absolute;
            top:0px;
            left:60px;
            z-index:99999;
            height:auto;
            display:none;
          }

        }
      }
      .menu-collapsed{
        flex:0 0 60px;
        width: 60px;
        background-color:rgb(50, 64, 87);
      }
      .menu-expanded{
        flex:0 0 230px;
        width: 230px;
        background-color:rgb(50, 64, 87);
      }
      .content-container {
        /*// background: #f1f2f7;*/
        flex:1;
        position: relative;
        /*// position: absolute;*/
        /*// right: 0px;
        // top: 0px;
        // bottom: 0px;
        // left: 230px;*/
        overflow-y: scroll;
        padding: 20px;
        .breadcrumb-container {
/*          //margin-bottom: 15px;*/
          .title {
            width: 200px;
            float: left;
            color: #475669;
          }
          .breadcrumb-inner {
            float: right;
          }
        }
        .content-wrapper {
          background: #fff;
          box-sizing: border-box;
        }
      }
    }
    .el-menu{
      background-color:#324057;
    }
    .el-menu .el-submenu__title{
      text-align: left;
    }
    .el-menu-item{
      color:#ffffff;
    }
    .el-menu-item:hover{
      color: #000000;

    }
  }
</style>

